package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IScaleDAO;
import com.AAL.Model.Scale;
import com.AAL.Utils.HibernateUtil;

public class ScaleDAO implements IScaleDAO {

	@Override
	public Scale getScale(int scaleID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Scale scale = (Scale) session.load(Scale.class, scaleID);
		return scale;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Scale> getAllScales() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Scale> lstScales = null;
		try {
			lstScales = (List<Scale>) session.createQuery("from Scale").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstScales;
	}

}
